package com.metaera.app.utils;


import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间
 */
public class DateUtils {

    public static final String
            PATTERN_3  = "yyyy.MM.dd HH:mm:ss", PATTERN_8 = "yyyy/MM/dd HH:mm:ss",
            PATTERN_2  = "yyyy-MM-dd",
            PATTERN_11 = "yyyy-MM",
            PATTERN_1  = "HH:mm MM/dd", PATTERN_7 = "HH:mm MM:dd",
            PATTERN_4  = "HH:mm",
            PATTERN_6  = "MM/dd", PATTERN_9 = "MM月dd日",
            PATTERN_10 = "MM-dd HH:mm",
            PATTERN_5  = "HH:mm:ss",
            PATTERN_12  = "dd";


    private DateUtils() {

    }

    /**
     * 根据时间戳获取时间字符串
     */
    public static String getTime(int timestamp, String pattern) {
        Log.i("DateUtils", String.format("date utils %d", timestamp));
        return new SimpleDateFormat(pattern).format(new Date(timestamp * 1000L));
    }

    /**
     * 根据时间戳获取当前星期
     * <p>
     * String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
     */
    public static String getWeekOfTimestamp(int timestamp, String[] weekDays) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(timestamp * 1000L));
        int week = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week < 0) week = 0;
        return weekDays[week];
    }

    /**
     * 是否为同一天
     */
    public static boolean isSameDate(int c, int n) {
        return c / (24 * 60 * 60) == n / (24 * 60 * 60);
    }

    /**
     * 是否为今天
     */
    public static boolean siToday(int timestamp) {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        return sf.format(new Date().getTime()).equals(sf.format(timestamp * 1000L));
    }

}
